package com.semanticweb.webapp.model.rbac;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

@Entity
@Table(name = "permissions")
public class Permission extends AbstractPersistedEntity {

	private static final long serialVersionUID = 894155229364881390L;

	@Version
	@Column(name = "version")
	private Integer version;

	@NotNull
	private String name;

	@ManyToMany(cascade = CascadeType.ALL)
	private Set<Role> roles = new HashSet<Role>();

	@ManyToOne
	private Object permissionObject;

	@ManyToOne
	private Operation permissionOperation;

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<Role> getRoles() {
		return this.roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	public Object getPermissionObject() {
		return this.permissionObject;
	}

	public void setPermissionObject(Object permissionObject) {
		this.permissionObject = permissionObject;
	}

	public Operation getPermissionOperation() {
		return this.permissionOperation;
	}

	public void setPermissionOperation(Operation permissionOperation) {
		this.permissionOperation = permissionOperation;
	}

	public Integer getVersion() {
		return this.version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String toString() {
		return ReflectionToStringBuilder.toString(this,
				ToStringStyle.SHORT_PREFIX_STYLE);
	}

}
